package reco.db.validation;

import static com.google.common.base.Preconditions.checkNotNull;

import org.apache.commons.validator.UrlValidator;

import reco.db.Constraint;

public class UrlConstraintFactory extends SimpleConstraintFactory implements StringConstraintFactory {

    private final UrlValidator validator;

    public UrlConstraintFactory(UrlValidator validator) {
        super(String.class);
        this.validator = checkNotNull(validator, "validator");
    }

    public UrlConstraintFactory() {
        this(new UrlValidator());
    }

    @Override
    protected <T> Constraint<T> createConstraint() {
        @SuppressWarnings("unchecked")
        // we already now T is String
        final Constraint<T> constraint = (Constraint<T>) new UrlConstraint(this.validator);

        return constraint;
    }
}